<?php

namespace App\Http\Controllers\Seller;

use App\Library\User\UserManagers;
use Illuminate\Http\Request;

class ProfileController extends BaseController
{
    use UserManagers;

    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->assign(['sideMenu' => 'profile']);
    }

    public function index()
    {
        $auth = $this->user()->auth()->firstOrCreate([]);
        if ($auth->auth_state == 0) {
            return redirect('seller/profile/edit');
        } else {
            return $this->view('seller.profile.index', ['auth' => $auth]);
        }
    }

    /**
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
     */
    public function edit(Request $request)
    {
        $auth = $this->user()->auth;
        if ($this->user()->auth_state) {
            return redirect('seller/profile');
        } else {
            return $this->view('seller.profile.edit', [
                'auth' => $auth
            ]);
        }
    }

    /**
     * @param Request $request
     * @param $auth
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    protected function savedAuthSuccess(Request $request, $auth)
    {
        return $this->messager()->setMessage(trans('user.auth info submit success'))->render();
    }
}
